package com.power.project.model;


import com.power.common.domain.BaseModel;
import com.power.project.enums.CustomNodeTypeEnum;
import com.power.project.interfaces.CustomNode;
import com.power.project.model.bo.DepartmentSaveBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 企业微信部门信息实体类
 */

@Entity
@ApiModel(value = "企业微信部门信息")
@Data
@Table(name = "Ww_depart")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
//@IdClass(Ww_depart.Ww_departPK.class) 用于复合组件
public class Ww_depart extends BaseModel implements Serializable, CustomNode {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false)
    @ApiModelProperty(value = "")
    private Integer id;

    @ApiModelProperty(value = "部门id")
    private String departid;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "部门负责人的userid")
    private String department_leader;

    @ApiModelProperty(value = "父级部门")
    private String parentid;

    @ApiModelProperty(value = "租户id")
    private String tenantid;

    @ApiModelProperty(value = "排序字段")
    private Integer sort_num;


    public Map<String, Object> parseMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", this.getId());
        map.put("departid", this.getId());
        map.put("name", this.getName());
        map.put("department_leader", this.getDepartment_leader());
        map.put("parentid", this.getParentid());
        map.put("tenantid", this.getTenantid());
        map.put("sort_num", this.getSort_num());
        return map;
    }

    public Serializable getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (Integer) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Ww_departPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (Integer) key;

        //Ww_departPK pk = (Ww_departPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

    public Ww_depart(DepartmentSaveBO saveBO, Integer sortNum) {
        this.departid = saveBO.getDepartId();
        this.name = saveBO.getName();
        this.parentid = saveBO.getParentId();
        this.tenantid = saveBO.getTenantId();
        this.sort_num = sortNum;
    }

    @Override
    public String getNodeId() {
        return this.departid;
    }

    @Override
    public String getParentNodeId() {
        return this.parentid;
    }

    @Override
    public String getNodeName() {
        return this.name;
    }

    @Override
    public Integer getNodeWeight() {
        return this.sort_num;
    }

    @Override
    public CustomNodeTypeEnum getType() {
        return CustomNodeTypeEnum.DEPART;
    }
}